import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import Antd from 'ant-design-vue'
import store from '@/store/index.js'
import 'ant-design-vue/dist/reset.css'
import "@/access/index.js"

const app = createApp(App)
import * as Icons from '@ant-design/icons-vue';
for (const i in Icons) {
  app.component(i, Icons[i]);
}

// 注册自定义指令 v-prevent-reclick 全局防抖
app.directive('prevent-reclick', {
  beforeMount(el, binding) {
    const delay = binding.value || 1500 // 获取传入的等待时间，默认为 1500 毫秒

    // 事件处理函数
    const handleClick = () => {
      if (el.disabled) return // 如果已经禁用，则不执行

      el.disabled = true // 禁用按钮
      el.classList.add('is-disabled') // Element Plus 可能需要手动添加类名

      setTimeout(() => {
        el.disabled = false // 重新启用按钮
        el.classList.remove('is-disabled') // 解除 Element Plus 的禁用样式
      }, delay)
    }

    el.__handleClick__ = handleClick // 把函数存到 `el` 上，方便解绑
    el.addEventListener('click', handleClick)
  },
  unmounted(el) {
    if (el.__handleClick__) {
      el.removeEventListener('click', el.__handleClick__)
      delete el.__handleClick__ // 清理引用
    }
  }
})
app.use(router)
app.use(Antd)
app.use(store)
app.mount('#app')
